# -*- coding: utf-8 -*-
# @Time    : 2021/3/2 16:29
# @Author  : AkromA
# @File    : get_computer_info.py
# @Software: PyCharm
# @Info    :

import socket


class GetComputerInfo:

    def __init__(self):
        self.get_name = socket.getfqdn(socket.gethostname())
        self.get_ip = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    # 获取本机电脑名
    def get_pcname(self):
        return self.get_name

    # 获取本机IP
    def get_myip(self):
        try:
            self.get_ip.connect(('8.8.8.8', 80))
            ip = self.get_ip.getsockname()[0]
        finally:
            self.get_ip.close()

        return ip


if __name__ == '__main__':
    print(GetComputerInfo().get_myip())
